1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.collect;
18
19 import com.google.common.annotations.GwtCompatible;
20
21 import java.util.Collection;
22 import java.util.Set;
23
24 import javax.annotation.Nullable;
25
26
27
28
29
30
31 @GwtCompatible(serializable = true, emulated = true)
32 final class EmptyImmutableSet extends ImmutableSet<Object> {
33 static final EmptyImmutableSet INSTANCE = new EmptyImmutableSet();
34
35 private EmptyImmutableSet() {}
36
37 @Override
38 public int size() {
39 return 0;
40 }
41
42 @Override public boolean isEmpty() {
43 return true;
44 }
45
46 @Override public boolean contains(@Nullable Object target) {
47 return false;
48 }
49
50 @Override public boolean containsAll(Collection<?> targets) {
51 return targets.isEmpty();
52 }
53
54 @Override public UnmodifiableIterator<Object> iterator() {
55 return Iterators.emptyIterator();
56 }
57
58 @Override boolean isPartialView() {
59 return false;
60 }
61
62 @Override
63 int copyIntoArray(Object[] dst, int offset) {
64 return offset;
65 }
66
67 @Override
68 public ImmutableList<Object> asList() {
69 return ImmutableList.of();
70 }
71
72 @Override public boolean equals(@Nullable Object object) {
73 if (object instanceof Set) {
74 Set<?> that = (Set<?>) object;
75 return that.isEmpty();
76 }
77 return false;
78 }
79
80 @Override public final int hashCode() {
81 return 0;
82 }
83
84 @Override boolean isHashCodeFast() {
85 return true;
86 }
87
88 @Override public String toString() {
89 return "[]";
90 }
91
92 Object readResolve() {
93 return INSTANCE;
94 }
95
96 private static final long serialVersionUID = 0;
97 }